--[[
File: WoWProStepFrames.lua
Author: Jahwo
Last Change: xx.xx.xxxx xx:xx

Summary: Creates and handles StepFrames
]]--



--[[		Creates a new StepFrame		]]--
function WoWPro:CreateStepFrame()

	local newBackdrop = {}
	newBackdrop.bgFile = "Interface\\Tooltips\\UI-Tooltip-Background"
	newBackdrop.tile = true
	newBackdrop.tileSize = 16
	
	local numFrames = #WoWPro.StepFrames
	
	local newParent = WoWPro_ScrollFrame_Frame
	if numFrames > 0 then newParent = WoWPro.StepFrames[numFrames] end
	
	
	---------- Frame ----------
	local newFrame = CreateFrame("Frame", "WoWPro_StepFrame" .. (numFrames + 1), newParent, nil)
	newFrame:ClearAllPoints()
	newFrame:SetPoint("TOPLEFT", newFrame:GetParent(), "BOTTOMLEFT")
	-- newFrame:SetBackdrop(newBackdrop)
	-- newFrame:SetBackdropColor(0.3, 0.3, 0.3, 0.6)
	
	
	---------- Main-Text Frame ----------
	newFrame.main = CreateFrame("Frame", newFrame:GetName() .. "_main", newFrame, nil)
	newFrame.main:ClearAllPoints()
	newFrame.main:SetPoint("TOPLEFT")
	newFrame.main:SetBackdrop(newBackdrop)
	newFrame.main:SetBackdropColor(0.1, 0.1, 0.1, 1)
	
	newFrame.main.text = newFrame.main:CreateFontString(newFrame.main:GetName() .. "_text", "OVERLAY")
	newFrame.main.text:SetFontObject("SystemFont_Med1")
	newFrame.main.text:SetJustifyH("LEFT")
	newFrame.main.text:SetJustifyV("TOP")
	newFrame.main.text:ClearAllPoints()
	newFrame.main.text:SetPoint("TOPLEFT", 5, -5)
	
	
	---------- Sub-Text Frame ----------
	newFrame.sub = CreateFrame("Frame", newFrame:GetName() .. "_sub", newFrame, nil)
	newFrame.sub:ClearAllPoints()
	newFrame.sub:SetPoint("TOPLEFT", newFrame.main, "BOTTOMLEFT", 15, -5)
	newFrame.sub:SetBackdrop(newBackdrop)
	newFrame.sub:SetBackdropColor(0.1, 0.1, 0.1, 1)
	
	newFrame.sub.text = newFrame.sub:CreateFontString(newFrame.sub:GetName() .. "_text", "OVERLAY")
	newFrame.sub.text:SetFontObject("SystemFont_Med1")
	newFrame.sub.text:SetJustifyH("LEFT")
	newFrame.sub.text:SetJustifyV("TOP")
	newFrame.sub.text:ClearAllPoints()
	newFrame.sub.text:SetPoint("TOPLEFT", 5, -5)
	
	
	------ TESTING! -----
	newFrame.main.text:SetText("!URight-click the |cFFFFAA44Warsong Battle Standard|r right away.|n|n!KDefend it until you get a complete message.|n|n!KKill some more in the village until you finish |cFFFFFF00[Scourge Armaments]|r.")
	newFrame.sub.text:SetText("!MGet out of |cFF33cc00Icemist Village|r.|nRide to southwest to a big stone building.")
	WoWPro:StepFrameChanged(newFrame)
	---------------------
	
	table.insert(WoWPro.StepFrames, newFrame)	
end 



--[[		Changes the Height and Width of a StepFrame to the right proportions		]]--
function WoWPro:StepFrameChanged(frame)
	local name = frame:GetName()							-- get the Frame name
	local main = frame.main									-- the maintext-Frame
	local sub = frame.sub									-- the subtext-Frame
	local maintext = main.text								-- the maintext
	local subtext = sub.text								-- the subtext
				
	frame:SetWidth(frame:GetParent():GetWidth())				-- Width of it's parent
	main:SetWidth(frame:GetWidth())								-- Width of the whole frame
	sub:SetWidth(frame:GetWidth() - 15)							-- Width of the whole frame - 15 because of the offset
	
	maintext:SetWidth(main:GetWidth() - 10)						-- Width - 10 because of Offset left and right
	subtext:SetWidth(sub:GetWidth() - 10)
	
	main:SetHeight(maintext:GetStringHeight() + 10)				-- StringHeight + 10 for Offset
	sub:SetHeight(subtext:GetStringHeight() + 10)				
	frame:SetHeight(main:GetHeight() + sub:GetHeight() + 20)	-- Both Heights + 20 for Offset between and spacing
end 



--[[		Called on sizechange of the whole Frame		]]--
function WoWPro:OnSizeChange()

	WoWPro_ScrollFrame_Frame:SetWidth(WoWPro_ScrollFrame_Frame:GetParent():GetWidth())	-- Set the ScrollFrame ScrollChild Frame's Width
	
	-- go through all StepFrames
	for k,v in pairs(WoWPro.StepFrames) do
		WoWPro:StepFrameChanged(v)
	end

end 